package com.amoqi.config;


import com.amoqi.controller.AjaxController;
import com.amoqi.controller.FileController;
import com.amoqi.controller.IndexController;
import com.amoqi.controller.UserController;
import com.amoqi.model.User;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.core.JFinal;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.ViewType;
import com.jfinal.template.Engine;

public class MainConfig extends JFinalConfig {

	@Override
	public void configConstant(Constants me) {
		me.setDevMode(true);
		me.setViewType(ViewType.JSP);
		me.setBaseUploadPath("amoqiUpload");
		PropKit.use("config.properties");
	}
	

	@Override
	public void configRoute(Routes me) {
		me.add("/", IndexController.class,"/");
		me.add("/user",UserController.class,"/page/user");
		me.add("/ajax",AjaxController.class,"/page/ajax");
		me.add("/file",FileController.class,"/page/file");

	}

	@Override
	public void configEngine(Engine me) {

	}

	@Override
	public void configPlugin(Plugins me) {
		C3p0Plugin c3p0Plugin = new C3p0Plugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password"));
		ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
		arp.addMapping("user", User.class);
		arp.setShowSql(true);
		me.add(c3p0Plugin);
		me.add(arp);
	}

	@Override
	public void configInterceptor(Interceptors me) {

	}

	@Override
	public void configHandler(Handlers me) {
		
	}
	
	public static void main(String[] args) {
		JFinal.start("WebRoot", 90, "/", 5);
	}

}
